import Vue from "vue";
import Vuex from "vuex";

import VuexPersistence from "vuex-persist";
import permission from "./modules/permission";
import user from "./modules/user";
import layout from "./modules/layout";
import getters from "./getters";
Vue.use(Vuex);

const vuexLocal = new VuexPersistence({
    key: "vuex",
    storage: window.localStorage,
});
const modulesNameList = ["PERMISSION", "USER", "LAYOUT"];
const store = new Vuex.Store({
    modules: {
        permission,
        user,
        layout,
    },
    state: {},
    mutations: {
        // 重置vuex所有state
        RESET_VUEX: () => {
            modulesNameList.forEach((item) => {
                store.commit(`${item}_RESET_STATE`);
            });
        },
    },
    actions: {},
    getters,
    plugins: [vuexLocal.plugin],
});
export default store;
